// 防抖
function debounce(fn, delay) {
    let timer = null;
    return function () {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(fn, delay);
    }
}

function debounce1(fn, delay, immediate = false) {
    let timer = null;
    return function(...args) {
        if(immediate && !timer) {
            fn.apply(this, args);
        } else {
            if(timer) clearTimeout(timer);
            timer = setTimeOut(()=>{
                fn.apply(this, args);
            },delay)
        }
    }
}

// 节流
function throttle(fn, delay) {
    let timer;
    return function () {
        if (!timer) {
            timer = setTimeout(() => {
                fn();
                timer = null;
            }, delay)

        }
    }
}




function throttle(fn, delay) {
    let lastTime = 0;
    return function () {
        let  = new Date().getTime();
        if (nowTime - lastTime > delay) {
            fun();
            lastTime = nowTime;
        }
    }
}